import {useSceneStore} from '@/stores/scene'
import { mittTypes } from '@/util/types';
let _this;
class actionControl{
    cacheMap= new Map();
    emitter= null;
    currentActionName = null;
    sceneStore=useSceneStore();
    constructor(emitter){
        this.emitter = emitter
        _this = this;
    }
    start(data){
        console.log(this.sceneStore.animationRefList)
        _this.emitter.emit(mittTypes.WEBHUMAN.ACTION_PLAY,data.action.data.actionName)
        this.currentActionName = data.action.data.actionName
    }
    update(data){
        _this.emitter.emit(mittTypes.WEBHUMAN.ACTION_SET_BY_TIME,{
            actionName:data.action.data.actionName,
            time:data.time
        })
        this.currentActionName = data.action.data.actionName

        // this.sceneStore.animationRefList.forEach(function(element){
        //     if(data.action.id == element.props.timelineData.actions[0].id){
        //         element.setAnimationByTime(data.time)
        //     }
        // })
    }
    stop(action){
        let actionName
        if(action){
            actionName= action.data.actionName
        }
         
        if(!action&&this.currentActionName){
            actionName = this.currentActionName
        }
        if(actionName){
            _this.emitter.emit(mittTypes.WEBHUMAN.ACTION_STOP,actionName)
        }else{
            console.log('当前没有动作需要暂停')
        }
        
        // this.sceneStore.animationRefList.forEach(function(element){
        //     if(data.action.id == element.props.timelineData.actions[0].id){
        //         element.stopAnimation()
        //     }
        // })
    }
    leave(action){
        this.currentActionName = null;
    }
}

export default actionControl;